<template>
    <div class="zuo">
        <van-sidebar v-model="active">
            <van-sidebar-item :title="item.cat_name" v-for="(item, index) in arr" :key="index" />
        </van-sidebar>
    </div>
    <div>
        <li v-for="(item, index) in arr[active]?.children" :key="index">{{ item.cat_name }}
            <van-grid :column-num="3">
                <van-grid-item v-for="(itme, indexs) in item.children" :key="indexs" :icon="itme.cat_icon" :text="itme.cat_name" @click="t(itme.cat_id)" />
            </van-grid>
        </li>
    </div>
</template>
<script setup>
import { ref } from 'vue';
import axios from 'axios';
import { useRouter } from 'vue-router';
let router = new useRouter()
let arr = ref([])
axios.get('https://api-hmugo-web.itheima.net/api/public/v1/categories').then(res => {
    arr.value = res.data.message
})
const t = (cid)=>{
    router.push({
        path: '/xq',
        query: {
            // url的参数, 类似get请求的传参
            cid
        },
    })
}
const active = ref(0);

</script>

<style>
.zuo {
    float: left;
}
</style> 